import axios from 'axios'
import { Toast } from 'mint-ui';

export function axiosGet(url, params, options) {

  return axios.get(url, {
    params: params,
    timeout: 10000
  })
    .then(response => {
      const data = response.data
      let _data
      if (typeof data === 'string') {
        if (params && params.type === 'agent') {
          _data = data
        } else {
          _data = JSON.parse(data)
        }
      } else {
        _data = data
      }

      if (!_data.success && _data.msg) {
          // Toast({
          //   message: _data.msg || '系统错误，请重试',
          //   duration: 3000
          // })
      }
      return _data
    })
}

export function axiosPost(url, params, options) {

  return axios.post(url, {
    params: params
  })
    .then(response => {
      const data = response.data
      let _data
      if (typeof data === 'string') {
        _data = JSON.parse(data)
      } else {
        _data = data
      }

      if (!_data.success && _data.msg) {
        // Toast({
        //   message: _data.msg || '系统错误，请重试',
        //   duration: 3000
        // })
      }
      return _data
    })
}
